<!DOCTYPE html>
<html lang="">

<head>
	<meta name="generator" content="Hugo 0.73.0" />
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<meta name="author" content="Ap Chen ">
<meta name="description" content="示例代码 // HelloWorld public class HelloWorld{ public static void main(String[] args){ System.out.println(&amp;#34;Hello World!&amp;#34;) } } " />
<meta name="keywords" content="blog" />
<meta name="robots" content="noodp" />

<link rel="canonical" href="https://fziks.gitee.io/notes/advanced-programming/java/" />

<meta itemprop="name" content="Java">
<meta itemprop="description" content="示例代码
// HelloWorld
public class HelloWorld{
    public static void main(String[] args){
        System.out.println(&#34;Hello World!&#34;)
    }
}
">
<meta itemprop="datePublished" content="2018-09-06T00:00:00&#43;00:00" />
<meta itemprop="dateModified" content="2018-09-06T00:00:00&#43;00:00" />
<meta itemprop="wordCount" content="1473">



<meta itemprop="keywords" content="java," />
<meta property="og:title" content="Java" />
<meta property="og:description" content="示例代码
// HelloWorld
public class HelloWorld{
    public static void main(String[] args){
        System.out.println(&#34;Hello World!&#34;)
    }
}
" />
<meta property="og:type" content="article" />
<meta property="og:url" content="https://fziks.gitee.io/notes/advanced-programming/java/" />
<meta property="article:published_time" content="2018-09-06T00:00:00+00:00" />
<meta property="article:modified_time" content="2018-09-06T00:00:00+00:00" />

<meta name="twitter:card" content="summary"/>
<meta name="twitter:title" content="Java"/>
<meta name="twitter:description" content="示例代码
// HelloWorld
public class HelloWorld{
    public static void main(String[] args){
        System.out.println(&#34;Hello World!&#34;)
    }
}
"/>


<link rel="apple-touch-icon" sizes="60x60" href="https://fziks.gitee.io/icons/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="https://fziks.gitee.io/icons/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="https://fziks.gitee.io/icons/favicon-16x16.png">
<link rel="manifest" href="https://fziks.gitee.io/icons/site.webmanifest">
<link rel="mask-icon" href="https://fziks.gitee.io/icons/safari-pinned-tab.svg" color="#5bbad5">
<link rel="shortcut icon" href="https://fziks.gitee.io/icons/favicon.ico">
<meta name="msapplication-TileColor" content="#ffffff">
<meta name="msapplication-config" content="/icons/browserconfig.xml">
<meta name="theme-color" content="#ffffff">

<title>Java</title>


<link rel="stylesheet" href="//at.alicdn.com/t/font_1559566_wk214kwa2dn.css">


    <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.css" integrity="sha384-zB1R0rpPzHqg7Kpt0Aljp8JPLqbXI3bhnPWROx27a9N0Ll6ZP/+DiW/UqRcLbRjq" crossorigin="anonymous">



    
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/8.0.1/normalize.css" integrity="sha256-WAgYcAck1C1/zEl5sBl5cfyhxtLgKGdpI3oKyJffVRI=" crossorigin="anonymous" />
    
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.7.2/animate.css" integrity="sha256-a2tobsqlbgLsWs7ZVUGgP5IvWZsx8bTNQpzsqCSm5mk=" crossorigin="anonymous" />
    
   <link href="https://stackpath.bootstrapcdn.com/bootswatch/4.4.1/materia/bootstrap.min.css" rel="stylesheet" integrity="sha384-1tymk6x9Y5K+OF0tlmG2fDRcn67QGzBkiM3IgtJ3VrtGrIi5ryhHjKjeeS60f1FA" crossorigin="anonymous">
    
    
    <link rel="stylesheet" href="https://fziks.gitee.io/sass/main_cdn.min.270b43bb8631af4497ed45b90db42c517e86c9511418de9152f134d02ed32b87.min.2192baea245cf318085511589e62bfbdb3fbe4fb0eef718f1be9af91c10542ce.css" integity="sha256-IZK66iRc8xgIVRFYnmK/vbP75PsO73GPG&#43;mvkcEFQs4=">

</head>

<body style="overflow-x: unset;">
	<div class="container-fluid">
		<div class="row d-print-block">
			<div class="col-12 col-md-3 col-lg-2 bd-sidebar d-print-none">
				<div class="d-flex mt-3 border-bottom">
        <span class="navbar-brand w-100" style="display: grid;">
            <small>
                <a href="https://fziks.gitee.io/" class="text-black-50">
                    <i class="iconfont icon-back-arrow-"></i>
                </a>
                Ap Chen's
            </small>
            <a class="text-dark" href="https://fziks.gitee.io/notes/">
                Notes
            </a>
        </span>
        <button class="btn btn-link text-dark d-md-none p-0 ml-3" type="button" data-toggle="collapse"
            data-target="#bd-docs-nav" aria-controls="bd-docs-nav" aria-expanded="true"
            aria-label="Toggle docs navigation">
            <i class="fad fa-bars"></i>
        </button>
    </div>
				<nav id="bd-docs-nav" class="collapse bd-links">
    
    
    
    <div class="bd-toc-item">
        <a class="bd-toc-link" href="https://fziks.gitee.io/notes/computer-network/">
            
            
                <span class="icontext">S</span>
            
            
            计算机网络
        </a>
    </div>
    
    
    
    <div class="bd-toc-item">
        <a class="bd-toc-link" href="https://fziks.gitee.io/notes/operating-system/">
            
            
                <span class="icontext">S</span>
            
            
            操作系统
        </a>
    </div>
    
    
    
    <div class="bd-toc-item">
        <a class="bd-toc-link" href="https://fziks.gitee.io/notes/database/">
            
            
                <span class="icontext">S</span>
            
            
            数据库
        </a>
    </div>
    
    
    
    <div class="bd-toc-item">
        <a class="bd-toc-link" href="https://fziks.gitee.io/notes/cs50-introduction-to-computer-science/">
            
            
                <span class="icontext">S</span>
            
            
            CS50 MIT
        </a>
    </div>
    
    
    
    <div class="bd-toc-item active bg-light">
        <a class="bd-toc-link" href="https://fziks.gitee.io/notes/advanced-programming/">
            <i class="iconfont icon-back-arrow-reverse"></i>
            高级程序设计
        </a>
        <ul class="nav bd-sidenav">
            
            
            <li>
                <a href="https://fziks.gitee.io/notes/advanced-programming/7-windows/">Windows</a>
            </li>
            
            
            
            <li>
                <a href="https://fziks.gitee.io/notes/advanced-programming/8-qt/">Qt</a>
            </li>
            
            
            
            <li class="active">
                <a href="https://fziks.gitee.io/notes/advanced-programming/java/">
                    <i class="fad fa-chevron-right mr-1"></i>
                    Java
                </a>
            </li>
            
            
        </ul>
    </div>
    
    
    
    <div class="bd-toc-item">
        <a class="bd-toc-link" href="https://fziks.gitee.io/notes/deep-learning/">
            
            
                <span class="icontext">O</span>
            
            
            深度学习基础
        </a>
    </div>
    
    
    
    <div class="bd-toc-item">
        <a class="bd-toc-link" href="https://fziks.gitee.io/notes/%E6%96%87%E7%8C%AE%E7%AE%A1%E7%90%86%E4%B8%8E%E4%BF%A1%E6%81%AF%E5%88%86%E6%9E%90/">
            
            
                <span class="icontext">O</span>
            
            
            文献管理与信息分析
        </a>
    </div>
    
    
</nav>
			</div>
			<div class="col-12 col-md-9 col-lg-10 d-print-block">
				<div class="row d-print-block">
					<main class="col-12 col-md-10 col-lg-9 py-md-3 pl-md-5 bd-content d-print-block" role="main">
						<div id="title" class="my-4 border-bottom">
							<span>高级程序设计</span>
							<h2>Java</h2>
							<footer>
								<span>
									<i class="iconfont icon-NewFile mr-2"></i>
									2018-09-06 08:00 CST
								</span> <br />
								<span>
									<i class="iconfont icon-modify mr-2"></i>
									2018-09-06 08:00 CST
								</span> <br />
								<span>
									<i class="iconfont icon-copyright mr-2"></i>
									CC BY-NC 4.0
								</span>
							</footer>
						</div>
						<div id="content" class="hl-h2">
							
							
							
							
							
							
							
							
							
							
							
							
							<h2 id="示例代码">示例代码<a href="#示例代码" class="anchor" aria-hidden="true"><i class="iconfont icon-link"></i></a></h2>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#8f5902;font-style:italic">// HelloWorld
</span><span style="color:#8f5902;font-style:italic"></span><span style="color:#204a87;font-weight:bold">public</span> <span style="color:#204a87;font-weight:bold">class</span> <span style="color:#000">HelloWorld</span><span style="color:#ce5c00;font-weight:bold">{</span>
    <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#204a87;font-weight:bold">static</span> <span style="color:#204a87;font-weight:bold">void</span> <span style="color:#000">main</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">String</span><span style="color:#ce5c00;font-weight:bold">[]</span> <span style="color:#000">args</span><span style="color:#ce5c00;font-weight:bold">){</span>
        <span style="color:#000">System</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">out</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">println</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;Hello World!&#34;</span><span style="color:#ce5c00;font-weight:bold">)</span>
    <span style="color:#ce5c00;font-weight:bold">}</span>
<span style="color:#ce5c00;font-weight:bold">}</span>
</code></pre></div><!-- raw HTML omitted -->
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#8f5902;font-style:italic">// A+B
</span><span style="color:#8f5902;font-style:italic"></span><span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">java.io.*</span><span style="color:#ce5c00;font-weight:bold">;</span>
<span style="color:#204a87;font-weight:bold">import</span> <span style="color:#000">java.util.*</span><span style="color:#ce5c00;font-weight:bold">;</span>

<span style="color:#204a87;font-weight:bold">public</span> <span style="color:#204a87;font-weight:bold">class</span> <span style="color:#000">Main</span>
<span style="color:#ce5c00;font-weight:bold">{</span>
    <span style="color:#204a87;font-weight:bold">public</span> <span style="color:#204a87;font-weight:bold">static</span> <span style="color:#204a87;font-weight:bold">void</span> <span style="color:#000">main</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">String</span> <span style="color:#000">args</span><span style="color:#ce5c00;font-weight:bold">[])</span> <span style="color:#204a87;font-weight:bold">throws</span> <span style="color:#000">Exception</span>
    <span style="color:#ce5c00;font-weight:bold">{</span>
        <span style="color:#000">Scanner</span> <span style="color:#000">cin</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#204a87;font-weight:bold">new</span> <span style="color:#000">Scanner</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">System</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">in</span><span style="color:#ce5c00;font-weight:bold">);</span>
        <span style="color:#204a87;font-weight:bold">int</span> <span style="color:#000">a</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#000">cin</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">nextInt</span><span style="color:#ce5c00;font-weight:bold">();</span>
        <span style="color:#204a87;font-weight:bold">int</span> <span style="color:#000">b</span><span style="color:#ce5c00;font-weight:bold">=</span><span style="color:#000">cin</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">nextInt</span><span style="color:#ce5c00;font-weight:bold">();</span>
        <span style="color:#000">System</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">out</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">println</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#000">a</span><span style="color:#ce5c00;font-weight:bold">+</span><span style="color:#000">b</span><span style="color:#ce5c00;font-weight:bold">);</span>
    <span style="color:#ce5c00;font-weight:bold">}</span>
<span style="color:#ce5c00;font-weight:bold">}</span>
</code></pre></div><h2 id="java-12-语法基础">Java 1.2 语法基础<a href="#java-12-语法基础" class="anchor" aria-hidden="true"><i class="iconfont icon-link"></i></a></h2>
<ul>
<li>基本类型--包装器
<ul>
<li>BigInteger, BigDecimal</li>
<li>对象储存在堆中</li>
<li>基本类型储存在栈中</li>
<li>包装器对象无法改变</li>
<li>(java5) 自动装包/拆包</li>
</ul>
</li>
<li>array
<ul>
<li>可在运行中确定大小</li>
</ul>
</li>
<li>.java 文件中的每个类，它们都有一个 .class 扩展名</li>
</ul>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#204a87;font-weight:bold">int</span><span style="color:#ce5c00;font-weight:bold">[]</span> <span style="color:#000">a</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">new</span> <span style="color:#204a87;font-weight:bold">int</span><span style="color:#ce5c00;font-weight:bold">[</span><span style="color:#000">100</span><span style="color:#ce5c00;font-weight:bold">];</span>
<span style="color:#204a87;font-weight:bold">int</span><span style="color:#ce5c00;font-weight:bold">[]</span> <span style="color:#000">a</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">new</span> <span style="color:#204a87;font-weight:bold">int</span><span style="color:#ce5c00;font-weight:bold">[]</span> <span style="color:#ce5c00;font-weight:bold">{</span><span style="color:#000">1</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">3</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">5</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">7</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">9</span><span style="color:#ce5c00;font-weight:bold">};</span>
<span style="color:#204a87;font-weight:bold">int</span><span style="color:#ce5c00;font-weight:bold">[]</span> <span style="color:#000">a</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#ce5c00;font-weight:bold">{</span><span style="color:#000">1</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">3</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">5</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">7</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">9</span><span style="color:#ce5c00;font-weight:bold">}</span>
<span style="color:#204a87;font-weight:bold">int</span><span style="color:#ce5c00;font-weight:bold">[][][]</span> <span style="color:#000">a2</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">new</span> <span style="color:#204a87;font-weight:bold">int</span><span style="color:#ce5c00;font-weight:bold">[</span><span style="color:#000">2</span><span style="color:#ce5c00;font-weight:bold">][</span><span style="color:#000">2</span><span style="color:#ce5c00;font-weight:bold">][</span><span style="color:#000">4</span><span style="color:#ce5c00;font-weight:bold">];</span>
</code></pre></div><ul>
<li>构造函数
<ul>
<li>this()</li>
<li>super()</li>
</ul>
</li>
<li>finalize()</li>
<li>基本数据初始化为0，对象引用初始化为 null</li>
<li>类中可定义初始值
<ul>
<li>成员必须初始化</li>
<li>先静态，再变量初始化，再构造函数</li>
</ul>
</li>
<li>静态块与匿名内部类初始化</li>
<li>protected 它本身是私有的，但可由从这个类继承的任何东西或者同一个包内的其他任何东西访问</li>
<li>单个编译单元内的所有类相互间都是自动“友好”的
<ul>
<li>包访问权限</li>
</ul>
</li>
<li>类只能 public 或 友好的
<ul>
<li>不愿他人访问：所有构造器设为 private, 用 static 初始化</li>
</ul>
</li>
<li>组合与继承</li>
<li>toString(): 非基本对象都有</li>
<li>向上转换：子类引用转为父类引用</li>
<li>final
<ul>
<li>基本数据类型：常数</li>
<li>对象引用：不可更改</li>
<li>final 函数：继承类不可修改</li>
<li>final class: 不可继承</li>
</ul>
</li>
<li>java 程序加载过程
<ul>
<li>递归找到基类</li>
<li>从基类开始初始化 static</li>
<li>创建对象
<ul>
<li>基本数据类型：默认值</li>
<li>对象引用：null</li>
</ul>
</li>
<li>从基类开始按序初始化实例对象</li>
<li>执行构造器剩余主体部分</li>
</ul>
</li>
<li>绑定
<ul>
<li>java 后期绑定</li>
<li>final 前期绑定</li>
</ul>
</li>
</ul>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#000">Shape</span> <span style="color:#000">s</span> <span style="color:#ce5c00;font-weight:bold">=</span> <span style="color:#204a87;font-weight:bold">new</span> <span style="color:#000">Circle</span><span style="color:#ce5c00;font-weight:bold">();</span>
<span style="color:#000">s</span><span style="color:#ce5c00;font-weight:bold">.</span><span style="color:#c4a000">draw</span><span style="color:#ce5c00;font-weight:bold">()</span>  <span style="color:#8f5902;font-style:italic">//circle&#39;s draw
</span></code></pre></div><ul>
<li>覆盖与重载</li>
<li>abstract 类</li>
<li>interface
<ul>
<li>不规定方法主体</li>
<li>可以 extends 其它接口</li>
<li>自动拥有 final static
<ul>
<li>不能是空白 final，但可以初始化成非常数表达式</li>
</ul>
</li>
</ul>
</li>
<li>内部类</li>
<li>向下转换
<ul>
<li>RTTI</li>
</ul>
</li>
<li>switch: char,int,enum</li>
</ul>
<h2 id="java-5">Java 5<a href="#java-5" class="anchor" aria-hidden="true"><i class="iconfont icon-link"></i></a></h2>
<ul>
<li>可变参数 <code>(type... name)</code>
<ul>
<li><code>int... data</code></li>
</ul>
</li>
<li>foreach 循环：<code>for (int x:data)</code></li>
<li>泛型：<code>Collection&lt;String&gt; c=new ArrayList&lt;String&gt;()</code>
<ul>
<li>Java中的泛型，只在编译阶段有效</li>
<li>泛型类 <code>public class Name&lt;T&gt;</code></li>
<li>泛型接口</li>
<li>泛型通配符 <code>&lt;?&gt;</code></li>
<li>泛型方法：public 与返回值之间的<code>&lt;T&gt;</code>必不可少，这表明这是一个泛型方法，并且声明了一个泛型T</li>
<li><code>&lt;A extends Number&gt;</code></li>
</ul>
</li>
<li>Enum
<ul>
<li>values()</li>
<li>valueOf()</li>
</ul>
</li>
</ul>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-Java" data-lang="Java"><span style="color:#204a87;font-weight:bold">enum</span> <span style="color:#000">Signal</span> <span style="color:#ce5c00;font-weight:bold">{</span>  
    <span style="color:#000">GREEN</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">YELLOW</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">RED</span>  
<span style="color:#ce5c00;font-weight:bold">}</span>

<span style="color:#204a87;font-weight:bold">public</span> <span style="color:#204a87;font-weight:bold">enum</span> <span style="color:#000">Color</span> <span style="color:#ce5c00;font-weight:bold">{</span>  
    <span style="color:#000">RED</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;红色&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">1</span><span style="color:#ce5c00;font-weight:bold">),</span> <span style="color:#000">GREEN</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;绿色&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">2</span><span style="color:#ce5c00;font-weight:bold">),</span> <span style="color:#000">BLANK</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;白色&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">3</span><span style="color:#ce5c00;font-weight:bold">),</span> <span style="color:#000">YELLO</span><span style="color:#ce5c00;font-weight:bold">(</span><span style="color:#4e9a06">&#34;黄色&#34;</span><span style="color:#ce5c00;font-weight:bold">,</span> <span style="color:#000">4</span><span style="color:#ce5c00;font-weight:bold">);</span>  
    <span style="color:#8f5902;font-style:italic">// 成员变量
</span><span style="color:#8f5902;font-style:italic"></span>    <span style="color:#8f5902;font-style:italic">// 构造方法  
</span><span style="color:#8f5902;font-style:italic"></span>    <span style="color:#8f5902;font-style:italic">// 普通方法  
</span><span style="color:#8f5902;font-style:italic"></span>    <span style="color:#8f5902;font-style:italic">// get set 方法  
</span><span style="color:#8f5902;font-style:italic"></span><span style="color:#ce5c00;font-weight:bold">}</span>
</code></pre></div><ul>
<li>注解：<code>@interface</code>
<ul>
<li>使用 <code>@name</code></li>
<li>元注解
<ul>
<li><code>@Retention</code>
<ul>
<li><code>RetentionPolicy.SOURCE</code></li>
<li><code>RetentionPolicy.CLASS</code></li>
<li><code>RetentionPolicy.RUNTIME</code></li>
</ul>
</li>
<li><code>@Documented</code></li>
<li><code>@Target</code></li>
<li><code>@Inherited</code></li>
<li><code>@Repeatable</code></li>
</ul>
</li>
<li>属性
<ul>
<li><code>int id();</code></li>
<li><code>int id() default -1;</code></li>
</ul>
</li>
<li>赋值方式：在括号内 <code>value=2</code></li>
<li>使用
<ul>
<li><code>Name.class.isAnnotationPresent(Annotationclass.class)</code></li>
<li><code>getAnnotation</code></li>
</ul>
</li>
<li><code>import static</code></li>
</ul>
</li>
<li>集合类
<ul>
<li>Arrays</li>
<li>Queue
<ul>
<li><code>Queue q = new LinkList();</code></li>
<li>offer, poll</li>
</ul>
</li>
</ul>
</li>
</ul>
<h2 id="集合类">集合类<a href="#集合类" class="anchor" aria-hidden="true"><i class="iconfont icon-link"></i></a></h2>
<ul>
<li>Legacy
<ul>
<li>Vector
<ul>
<li>size()</li>
<li>addElement()</li>
<li>elementAt()</li>
<li>elements(): 返回迭代器</li>
</ul>
</li>
<li>Bitset</li>
<li>Stack</li>
<li>Hashtable</li>
<li>迭代器
<ul>
<li>Enumeration
<ul>
<li>nextElement()</li>
<li>hasMoreElements()</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
<li>Collection
<ul>
<li>List 顺序
<ul>
<li>ArrayList</li>
<li>LinkedList
<ul>
<li>addFirst()，addLast()，getFirst()，getLast()，removeFirst(),removeLast()</li>
</ul>
</li>
</ul>
</li>
<li>Set
<ul>
<li>内部对象必须定义 equals()</li>
<li>HashSet</li>
<li>TreeSet</li>
<li>ArraySet</li>
</ul>
</li>
</ul>
</li>
<li>Map
<ul>
<li>HashMap</li>
<li>ArrayMap</li>
<li>TreeMap</li>
</ul>
</li>
<li>Comparable
<ul>
<li>Comparator</li>
</ul>
</li>
</ul>
<h3 id="collection-方法">Collection 方法<a href="#collection-方法" class="anchor" aria-hidden="true"><i class="iconfont icon-link"></i></a></h3>
<ul>
<li>boolean add(Object) ＊保证集合内包含了参数。如果它没有添加参数，就返回false（假）</li>
<li>boolean addAll(Collection) ＊添加参数内的所有元素。如果没有添加元素，则返回true（真）</li>
<li>void clear() ＊删除集合内的所有元素</li>
<li>boolean contains(Object) 若集合包含参数，就返回“真”</li>
<li>boolean containsAll(Collection) 若集合包含了参数内的所有元素，就返回“真”</li>
<li>boolean isEmpty() 若集合内没有元素，就返回“真”</li>
<li>Iterator iterator() 返回一个迭代器，以用它遍历集合的各元素</li>
<li>boolean remove(Object) ＊如参数在集合里，就删除那个元素的一个实例。如果已进行了删除，就返回“真”</li>
<li>boolean removeAll(Collection) ＊删除参数里的所有元素。如果已进行了任何删除，就返回“真”</li>
<li>boolean retainAll(Collection) ＊只保留包含在一个参数里的元素（一个理论的“交集”）。如果已进行了任何改变，就返回“真”</li>
<li>int size() 返回集合内的元素数量</li>
<li>Object[] toArray() 返回包含了集合内所有元素的一个数组</li>
</ul>
<h3 id="list-方法">List 方法<a href="#list-方法" class="anchor" aria-hidden="true"><i class="iconfont icon-link"></i></a></h3>
<ul>
<li>get()</li>
<li>indexof()</li>
<li>lastIndexOf()</li>
<li>listIterator()</li>
<li>set()</li>
</ul>
<h2 id="io">IO<a href="#io" class="anchor" aria-hidden="true"><i class="iconfont icon-link"></i></a></h2>
<ul>
<li>InputStream (Reader:InputStreamReader)
<ul>
<li>ByteArrayInputStream (CharArrayReader)</li>
<li>StringBufferInputStream (StringReader)
<ul>
<li>int read()</li>
</ul>
</li>
<li>StringBuffer</li>
<li>FileInputStream (FileReader)</li>
<li>PipedInputStream (PipeReader)</li>
<li>SequenceInputStream</li>
<li>FilterInputStream (FilterReader)
<ul>
<li>DataInputStream
<ul>
<li>-readLine()</li>
<li>available()</li>
</ul>
</li>
<li>BufferedInputStream (BufferedReader:readLine())</li>
<li>LineNumberInputStream (LineNumberInputReader)</li>
<li>PushBackInputStream (PushBackReader)</li>
</ul>
</li>
<li>InflaterInputStream
<ul>
<li>CheckedInputStream</li>
<li>ZipInputStream</li>
<li>GZIPInputStream</li>
</ul>
</li>
</ul>
</li>
<li>OutputStream (Writer:OutputStreamWriter)
<ul>
<li>ByteArrayOutputStream (CharArrayWriter)</li>
<li>FileOutputStream (FileWriter)</li>
<li>PipedOutputStream (PipeWriter)</li>
<li>FilterOutputStream</li>
<li>FilterInputStream (FilterWriter)
<ul>
<li>DataOutputStream
<ul>
<li>writeBytes()</li>
<li>writeDouble()</li>
</ul>
</li>
<li>BufferedOutputStream (BufferedWriter)</li>
<li>OutputStream</li>
<li>PrintStream (PrintWriter)</li>
</ul>
</li>
<li>DeflaterOutputStream
<ul>
<li>CheckedOutputStream</li>
<li>ZipOutputStream</li>
<li>GZIPOutputStream</li>
</ul>
</li>
</ul>
</li>
<li>RandomAccessFile</li>
<li>StreamTokenizer
<ul>
<li>StringTokenizer</li>
</ul>
</li>
<li>System
<ul>
<li>in: InputStream</li>
<li>out: PrintStream</li>
<li>err: PrintStream</li>
<li>setIn/setOut/setErr</li>
<li>(java5) Scanner
<ul>
<li>nextLine()</li>
<li>hasNext()</li>
</ul>
</li>
</ul>
</li>
</ul>
<h2 id="java-7">Java 7<a href="#java-7" class="anchor" aria-hidden="true"><i class="iconfont icon-link"></i></a></h2>
<ul>
<li>多个异常： <code>catch (ExceptionA | ExceptionB a)</code></li>
<li>try-with-resource</li>
</ul>
<h2 id="lamdba-表达式-java-8">Lamdba 表达式 (Java 8)<a href="#lamdba-表达式-java-8" class="anchor" aria-hidden="true"><i class="iconfont icon-link"></i></a></h2>
<ul>
<li>(parameters) -&gt; expression</li>
<li>(parameters) -&gt;{ statements; }</li>
</ul>
<h2 id="clone">Clone<a href="#clone" class="anchor" aria-hidden="true"><i class="iconfont icon-link"></i></a></h2>
<ul>
<li>clone()</li>
<li>clonable 接口</li>
</ul>
<h2 id="class">Class<a href="#class" class="anchor" aria-hidden="true"><i class="iconfont icon-link"></i></a></h2>
<ul>
<li>instanceof</li>
</ul>
<h2 id="注释文档">注释文档<a href="#注释文档" class="anchor" aria-hidden="true"><i class="iconfont icon-link"></i></a></h2>
<ul>
<li>/** */</li>
<li>支持 HTML</li>
<li>@see</li>
<li>class
<ul>
<li>@version</li>
<li>@author</li>
</ul>
</li>
<li>method
<ul>
<li>@param</li>
<li>@return</li>
<li>@exception</li>
<li>@deprecated</li>
</ul>
</li>
</ul>
<h2 id="命令行工具">命令行工具<a href="#命令行工具" class="anchor" aria-hidden="true"><i class="iconfont icon-link"></i></a></h2>
<ul>
<li>编译<code>javac name.java; java name</code></li>
<li>命令行请求 public 类时，调用的是 main()</li>
</ul>
<h2 id="thread">Thread<a href="#thread" class="anchor" aria-hidden="true"><i class="iconfont icon-link"></i></a></h2>
<ul>
<li>synchronized</li>
<li>wait()</li>
<li>notify()</li>
<li>Thread
<ul>
<li>run(): 需要重写</li>
<li>start()</li>
<li>yield()</li>
<li>join()</li>
</ul>
</li>
<li>Runnable</li>
<li>(Java5) java.util.concurrent
<ul>
<li>ThreadLocal</li>
<li>AtomicInteger</li>
<li>Lock
<ul>
<li>ReentrantLock</li>
<li>ReentrantReadWriteLock.ReadLock</li>
<li>ReentrantReadWriteLock.WriteLock</li>
</ul>
</li>
<li>BlockingQueue</li>
<li>ConcurrentHashMap</li>
<li>ThreadPoolExecutor
<ul>
<li>corePoolSize: 核心池的大小</li>
<li>maximumPoolSize</li>
<li>KeepAliveTime</li>
<li>ExecutorService
<ul>
<li>Executors.newCachedThreadPool()</li>
<li>Executors.newFixedThreadPool(3)</li>
<li>Executors.newScheduledThreadPool(5);</li>
<li>Executors.newSingleThreadExecutor();</li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<h2 id="网络">网络<a href="#网络" class="anchor" aria-hidden="true"><i class="iconfont icon-link"></i></a></h2>
<ul>
<li>InetAddress.getByName()
<ul>
<li>InetAddress.getByName(null); localhost</li>
</ul>
</li>
<li>ServerSocket</li>
<li>Socket</li>
</ul>

						</div>
					</main>
					<div class="d-none d-lg-block col-lg-3 bd-toc d-print-none">
						<div class="btn-group-vertical w-100 my-3">
    
    <a class="btn btn-outline-secondary text-dark w-100 p-2" href="https://list.html" target="_blank">
        <i class="iconfont icon-LC_icon_list_line"></i><br />待更新列表
    </a>
    

    
    <a class="btn btn-outline-secondary text-dark w-100 p-2" href="mailto:littlegreedy@qq.com"
        target="_blank">
        <i class="iconfont icon-discussion"></i><br />纠错与咨询
    </a>
    
    
    
    
        <a class="btn btn-outline-secondary text-dark w-100 p-2" href="#" onclick="window.print()">
            <i class="iconfont icon-dayin"></i><br />打印本页
        </a>
    
    
</div>
						<h4 class="card-title pb-0">目录</h4>
						<nav id="TableOfContents">
  <ul>
    <li><a href="#示例代码">示例代码</a></li>
    <li><a href="#java-12-语法基础">Java 1.2 语法基础</a></li>
    <li><a href="#java-5">Java 5</a></li>
    <li><a href="#集合类">集合类</a>
      <ul>
        <li><a href="#collection-方法">Collection 方法</a></li>
        <li><a href="#list-方法">List 方法</a></li>
      </ul>
    </li>
    <li><a href="#io">IO</a></li>
    <li><a href="#java-7">Java 7</a></li>
    <li><a href="#lamdba-表达式-java-8">Lamdba 表达式 (Java 8)</a></li>
    <li><a href="#clone">Clone</a></li>
    <li><a href="#class">Class</a></li>
    <li><a href="#注释文档">注释文档</a></li>
    <li><a href="#命令行工具">命令行工具</a></li>
    <li><a href="#thread">Thread</a></li>
    <li><a href="#网络">网络</a></li>
  </ul>
</nav>
						
						
						<div id="disqus_thread"></div>
							<script>
							

							

							(function() { 
							var d = document, s = d.createElement('script');
							s.src = "https://"+"your site name on disqus"+".disqus.com/embed.js";
							s.setAttribute('data-timestamp', +new Date());
							(d.head || d.body).appendChild(s);
							})();
							</script>
							<noscript>Please enable JavaScript to view the <a href="https://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript>                  
					  	</div>
						
					</div>
				</div>
			</div>
		</div>
	</div>

	<script
    src="https://code.jquery.com/jquery-3.4.1.min.js"
    integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo="
    crossorigin="anonymous"></script><script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/js/bootstrap.min.js" integrity="sha384-JjSmVgyd0p3pXB1rRibZUAYoIIy6OrQ6VrjIEaFf/nJGzIxFDsf4x0xIM+B07jRM" crossorigin="anonymous"></script><script defer src="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/katex.min.js" integrity="sha384-y23I5Q6l+B6vatafAwxRu/0oK/79VlbSz7Q9aiSZUvyWYIYsd+qj+o24G5ZU2zJz" crossorigin="anonymous"></script>
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.11.1/dist/contrib/auto-render.min.js" integrity="sha384-kWPLUVMOks5AQFrykwIup5lo0m3iMkkHrD0uJ4H5cjeGihAutqP0yW0J6dpFiVkI" crossorigin="anonymous"
onload="renderMathInElement(document.body);"></script>

<script type="text/javascript" src="https://fziks.gitee.io/custom.min.d3e1b7647f32dbe7e0140398739a26dad3f3470fc1eebe0741ef33668f1b7bd0b2917dc6efb9f0d9f1092b91dca502cab1b883863f02530133a8a8ef609926af.js" integrity="sha512-0&#43;G3ZH8y2&#43;fgFAOYc5om2tPzRw/B7r4HQe8zZo8be9CykX3G77nw2fEJK5HcpQLKsbiDhj8CUwEzqKjvYJkmrw=="></script>
<script type="text/javascript">

document.addEventListener("DOMContentLoaded", function () {
    renderMathInElement(
        document.body, {
            delimiters: [
                {
                    left: "$$",
                    right: "$$",
                    display: true
                },
                {
                    left: "\\[",
                    right: "\\]",
                    display: true
                },
                {
                    left: "$",
                    right: "$",
                    display: false
                },
                {
                    left: "\\(",
                    right: "\\)",
                    display: false
                }
            ],
            strict: false
        }
    );
});


$(document).on('click', 'a[href^="#"]', function (event) {
    event.preventDefault();

    $('html, body').animate({
        scrollTop: $($.attr(this, 'href')).offset().top
    }, 500);
});
</script>




</body>

</html>